﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace StreetSmartAdmin
{
    public class Result
    {
        public string Operator { get; set; }
        public int TotalResult {get; set; }
        public int DayResult { get; set; }
        public int MonthResult { get; set; }
    }


    public partial class Display : System.Web.UI.Page
    {
        static String date = DateTime.Now.Date.ToString("yyyy-MM-dd ");
        static String year = DateTime.Now.Year.ToString();
        static String month = date.Substring(5, 2);
        static String monthStart = year + month + "01";
        static String monthEnd = year + month + "31";
    
        /*
        public static String totalresult;
        public static String total1result;
        public static String total2result;
        public static String total3result;
        public static String monthresult;
        public static String month1result;
        public static String month2result;
        public static String month3result;
        public static String dayresult;
        public static String day1result;
        public static String day2result;
        public static String day3result;
        */

        public static int AllDayResult;
        public static int AllMonthResult;
        public static int AllResult;

        public static String resNmberResult;
        public static String busNumberResult;
        public static String comNumberResult;
        public static String totalNumberResult;

        public static String resValueResult;
        public static String busValueResult;
        public static String comValueResult;
        public static String totalValueResult;

        public static String resEleResult;
        public static String busEleResult;
        public static String comEleResult;
        public static String totalEleResult;

        public static String resGasResult;
        public static String busGasResult;
        public static String comGasResult;
        public static String totalGasResult;

        public static String resTotResult;
        public static String busTotResult;
        public static String comTotResult;
        public static String totalTotResult;

        public List<string> OpertorDisplay = new List<string>();
        public List<Result> ResultDisplay = new List<Result>();
        protected void Page_Load(object sender, EventArgs e)
        {
            //((Label)Header.FindControl("lblUser")).Text = ((Userinfo)Session["UserInfo"]).fullname; 
            //((Label)Header.FindControl("lblUser")).Text = ((String)Session["UserName"]);
            ((Label)Header.FindControl("lblUser")).Text = (User.Identity.Name);
            AllDayResult = 0;
            AllMonthResult = 0;
            AllResult = 0;
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLServer2005DBConnectionString"];
                string connectionString = connString.ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                command.CommandText = "usp_GetTotalValue";
                command.CommandType = System.Data.CommandType.StoredProcedure;
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                resNmberResult = Convert.ToString(reader["RESICount"]);
                busNumberResult = Convert.ToString(reader["SMECount"]);
                comNumberResult = Convert.ToString(reader["CICount"]);
                totalNumberResult = Convert.ToString(reader["TotalCount"]);


                 resEleResult= Convert.ToString(reader["RESICountELE"]);
                 busEleResult = Convert.ToString(reader["SMECountELE"]);
                 comEleResult = Convert.ToString(reader["CICountELE"]);
                 totalEleResult = Convert.ToString(reader["TotalCountELE"]);

                 resGasResult = Convert.ToString(reader["RESICountGAS"]);
                 busGasResult = Convert.ToString(reader["SMECountGAS"]);
                 comGasResult = Convert.ToString(reader["CICountGAS"]);
                 totalGasResult = Convert.ToString(reader["TotalCountGAS"]);

                 resTotResult = Convert.ToString(reader["RESICountTOT"]);
                 busTotResult = Convert.ToString(reader["SMECountTOT"]);
                 comTotResult = Convert.ToString(reader["CICountTOT"]);
                 totalTotResult = Convert.ToString(reader["TotalCountTOT"]);








                resValueResult = Convert.ToString(reader["RESIValue"]);
                resValueResult = Convert.ToInt32(resValueResult).ToString("C");
                busValueResult = Convert.ToString(reader["SMEValue"]);
                busValueResult = Convert.ToInt32(busValueResult).ToString("C");
                comValueResult = Convert.ToString(reader["CIValue"]);
                comValueResult = Convert.ToInt32(comValueResult).ToString("C");
                totalValueResult = Convert.ToString(reader["DollarValue"]);
                totalValueResult = Convert.ToInt32(totalValueResult).ToString("C");

                reader.Close();

                command.CommandText = "select OperatorName from tblOperator where Display=1";
                command.CommandType = System.Data.CommandType.Text;
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    OpertorDisplay.Add(Convert.ToString(reader["OperatorName"]));
                }
                reader.Close();

                command.CommandText = "usp_GetConverted";
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@operator", System.Data.SqlDbType.VarChar));
                command.Parameters.Add(new SqlParameter("@date", System.Data.SqlDbType.VarChar));
                command.Parameters.Add(new SqlParameter("@monthStart", System.Data.SqlDbType.VarChar));
                command.Parameters.Add(new SqlParameter("@monthEnd", System.Data.SqlDbType.VarChar));


                foreach (string Operator in OpertorDisplay)
                {
                    command.Parameters["@operator"].Value = Operator;
                    command.Parameters["@date"].Value = date;
                    command.Parameters["@monthStart"].Value = monthStart;
                    command.Parameters["@monthEnd"].Value = monthEnd;
                    reader = command.ExecuteReader();
                    reader.Read();
                    Result result = new Result();
                    result.Operator = Operator;
                    result.DayResult = Convert.ToInt16(reader["dayTotal"]);
                    result.MonthResult = Convert.ToInt16(reader["monthTotal"]);
                    result.TotalResult = Convert.ToInt16(reader["total"]);
                    AllDayResult += result.DayResult;
                    AllMonthResult += result.MonthResult;
                    AllResult += result.TotalResult;
                    ResultDisplay.Add(result);
                    reader.Close();
                }

            /*
                command.CommandText = "usp_GetConvertedNum";
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@date", System.Data.SqlDbType.VarChar));
                command.Parameters.Add(new SqlParameter("@monthStart", System.Data.SqlDbType.VarChar));
                command.Parameters.Add(new SqlParameter("@monthEnd", System.Data.SqlDbType.VarChar));
                command.Parameters["@date"].Value = date;
                command.Parameters["@monthStart"].Value = monthStart;
                command.Parameters["@monthEnd"].Value = monthEnd;
                reader = command.ExecuteReader();
                reader.Read();
                totalresult = Convert.ToString(reader["total"]);
                total1result = Convert.ToString(reader["total1"]);
                total2result = Convert.ToString(reader["total2"]);
                total3result = Convert.ToString(reader["total3"]);
                monthresult = Convert.ToString(reader["monthTotal"]);
                month1result = Convert.ToString(reader["monthTotal1"]);
                month2result = Convert.ToString(reader["monthTotal2"]);
                month3result = Convert.ToString(reader["monthTotal3"]);
                dayresult = Convert.ToString(reader["day0"]);
                day1result = Convert.ToString(reader["day1"]);
                day2result = Convert.ToString(reader["day2"]);
                day3result = Convert.ToString(reader["day3"]);
                reader.Close();
             */
                connection.Close();
        }
    }
}